package com.zhanglu.fun.services.datacenter.forumthread;

import com.zhanglu.fun.services.datacenter.entity.ForumThread;
import com.zhanglu.fun.services.datacenter.enums.ThreadsGroup;
import com.zhanglu.fun.services.datacenter.enums.ThreadsStatus;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zhanglu.fun.services.datacenter.common.ResultResponse;
import com.zhanglu.fun.tookit.json.JsonTools;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jing
 * @description 主题controller
 * @date 2017/6/26 0026 23:21
 */
@RestController
@Slf4j
public class ForumThreadRouter {
    @Autowired
    private ForumThreadService forumThreadService;

    @ApiOperation(value = "查询主题", notes = "根据条件查询主题信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "内容、标题、用户昵称等的模糊匹配", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "threadGroup", value = "主题分组", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "主题状态", required = false, dataType = "String", paramType = "query") })
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = ResultResponse.class) })
    @GetMapping("/forum/threads")
    public ResultResponse getForumThreads(@RequestParam(value = "content",required = false) String content,
                                          @RequestParam(value = "threadGroup",required = false) ThreadsGroup threadGroup,
                                          @RequestParam(value = "status",required = false) ThreadsStatus status) {
        ForumThread thread = new ForumThread().setContent(content).setThreadGroup(threadGroup).setStatus(status);
        log.info("getForumThreads receive params:[forumThread json is:{}]", JsonTools.toJSONString(thread));
        return forumThreadService.getForumThreads(thread);
    }

    @ApiOperation(value = "删除主题", notes = "根据条件删除主题信息")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Long", paramType = "query") })
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = ResultResponse.class) })
    @DeleteMapping("/forum/threads")
    public ResultResponse deleteForumThread(@RequestParam("id") Long id) {
        log.info("deleteForumThread receive params:[id:{}]", id);
        return forumThreadService.deleteForumThread(id);
    }

    @ApiOperation(value = "添加主题", notes = "添加主题")
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = ResultResponse.class) })
    @PutMapping("/forum/thread")
    public ResultResponse addForumThread(@RequestBody ForumThread forumThread) {
        log.info("addForumThread receive params:[forumThread json is:{}]", JsonTools.toJSONString(forumThread));
        return forumThreadService.addForumThread(forumThread);
    }

    @ApiOperation(value = "修改主题", notes = "修改主题")
    @ApiResponses({ @ApiResponse(code = 200, message = "请求成功", response = ResultResponse.class) })
    @PostMapping("/forum/thread")
    public ResultResponse updateForumThread(@RequestBody ForumThread forumThread) {
        log.info("updateForumThread receive params:[forumThread json is:{}]", JsonTools.toJSONString(forumThread));
        return forumThreadService.updateForumThread(forumThread);
    }
}
